import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '../views/Main.vue'

Vue.use(VueRouter)


// 解决重复点击相同路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export const MainChildren = [{
    path: 'home',
    name: 'home',
    meta: {
      title: '首页'
    },
    component: () => import('../views/Home.vue'),
  },
  {
    path: 'product',
    name: 'product',
    meta: {
      title: '产品管理'
    },
    component: () => import('../views/productManage/Index.vue'),
    children: [{
      path: 'list',
      name: 'productList',
      meta: {
        title: '产品列表'
      },
      component: () => import('../views/productManage/ProductList.vue'),
    }, {
      path: 'type',
      name: 'productType',
      meta: {
        title: '修改分类'
      },
      component: () => import('../views/productManage/ProductType.vue'),
    }]
  },
  {
    path: 'indent',
    name: 'indent',
    meta: {
      title: '订单管理'
    },
    component: () => import('../views/indentManage/Index.vue'),
    children: [{
      path: 'count',
      name: 'indentCount',
      meta: {
        title: '订单总数'
      },
      component: () => import('../views/indentManage/IndentCount.vue'),
    }, {
      path: 'list',
      name: 'indentList',
      meta: {
        title: '订单列表'
      },
      component: () => import('../views/indentManage/IndentList.vue'),
    }]
  },
  {
    path: 'advert',
    name: 'advert',
    meta: {
      title: '广告管理'
    },
    component: () => import('../views/advertManage/Index.vue'),
    children: [{
      path: 'list',
      name: 'advertList',
      meta: {
        title: '广告列表'
      },
      component: () => import('../views/advertManage/AdvertList.vue'),
    }]
  }


]

const routes = [{
    path: '/',
    name: 'Main',
    redirect: '/home',
    component: Main,
    children: MainChildren
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  }
]


const router = new VueRouter({
  routes
})

export default router